<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        // ES6提供的flat方法
        let arr = [1, 2, [3, 4], [5, 6]]

        function fn(arr) {
            return arr.flat(Infinity)
        }
        // console.log(fn(arr));

        // 使用JSON的函数和正则表达式
        function flatten(arr) {
            let result = JSON.stringify(arr).replace(/(\[|\])/g, '');
            result = '[' + result + ']';
            return JSON.parse(result);
        }
         console.log(flatten(arr));

         
    </script>
</body>

</html>